package com.leyou.page.listener;

import com.leyou.common.constants.MQConstants;
import com.leyou.page.service.PageService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PageListener {

    @Autowired
    private PageService pageService;


    /*监听商品上架，创建商品详情静态页面*/
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MQConstants.Queue.PAGE_ITEM_UP,durable = "true"),
            exchange=@Exchange(name = MQConstants.Exchange.ITEM_EXCHANGE_NAME,type = ExchangeTypes.TOPIC),
            key = {MQConstants.RoutingKey.ITEM_UP_KEY}
    ))
    public void insertHtml(Long spuId){

        pageService.createHTML(spuId);
    }

    /*监听商品下架，删除商品详情页面*/
    @RabbitListener(bindings=@QueueBinding(
            value = @Queue(name = MQConstants.Queue.PAGE_ITEM_DOWN,durable = "true"),
            exchange=@Exchange(name = MQConstants.Exchange.ITEM_EXCHANGE_NAME,type = ExchangeTypes.TOPIC),
            key = {MQConstants.RoutingKey.ITEM_DOWN_KEY}
    ))
    public void deleteHtml(Long spuId){

        pageService.deleteHTML(spuId);
    }

}


